<template>
    <div>
        <el-dialog
        :visible.sync="value"
        width="600px">
            <div class="from">
                <el-form :model="form"
                label-width="80px">
                    <el-form-item label="标题">
                        <el-input v-model="form.title" placeholder="标题"></el-input>
                    </el-form-item>
                    <el-form-item label="类型">
                        <el-input v-model="form.type" placeholder="类型"></el-input>
                    </el-form-item>
                    <el-form-item label="所属" v-if="second">
                        <el-input v-model="form.secondId" placeholder="所属精选"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('input', false)">取 消</el-button>
                <el-button type="primary" @click="handleEdit(form)">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { mapState } from 'vuex'
    import { editHome } from '@/api/home'
    export default {
        props : {
            value : {
                type : Boolean,
                default : false
            },
            second : {
                type : Boolean,
                default : false
            },
            form : {
                type : Object,
                default : {
                    secondId : undefined,
                    title : undefined,
                    banners : undefined,
                    menus : undefined,
                    type : undefined,
                }
            }
        },
        computed:{
            ...mapState(['dataType'])
        },
        data() {
            return {
                
            }
        },
        created(){

        },
        methods : {
            handleEdit(form){
                if(!form.title){
                    this.$message.error('标题不能为空')
                    return
                }
                if(!form.type){
                    this.$message.error('类型不能为空')
                    return
                }
                form.secondId = this.$route.query.id || undefined
                editHome(form).then(res => {
                    if(res.code == 200){
                        this.$emit('success', res)
                        this.$message.success('操作成功')
                    }
                    this.$emit('input', false)
                })
            },
        },
    }
</script>

<style lang="less" scoped>

</style>